﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ECommerce.Reflection
{
    public class ItemTipo
    {
        public ItemTipo(Type tipo, string value)
        {
            this.Tipo = tipo;
            this.Value = value;
        }
        public Type Tipo;
        private string value;
        public string Value
        {
            get { return this.value; }
            set { this.value = value; }
        }
        public string Name
        {
            get { return this.Tipo.ToString(); }
        }
        public override string ToString()
        {
            return this.Tipo.ToString();
        }
    }
    public static class Tipos
    {
        public static ECommerce.Reflection.ItemTipo[] GetSystemTipos()
        {
            List<ECommerce.Reflection.ItemTipo> result = new List<ECommerce.Reflection.ItemTipo>();
            result.Add(new ECommerce.Reflection.ItemTipo(typeof(System.Web.UI.WebControls.TextBox), "0"));
            result.Add(new ECommerce.Reflection.ItemTipo(typeof(System.Web.UI.WebControls.Label), "1"));
            result.Add(new ECommerce.Reflection.ItemTipo(typeof(System.Web.UI.WebControls.LinkButton), "2"));
            result.Add(new ECommerce.Reflection.ItemTipo(typeof(System.Web.UI.WebControls.Button), "3"));
            result.Add(new ECommerce.Reflection.ItemTipo(typeof(System.Web.UI.WebControls.ImageButton), "4"));
            result.Add(new ECommerce.Reflection.ItemTipo(typeof(System.Web.UI.WebControls.Image), "5"));
            result.Add(new ECommerce.Reflection.ItemTipo(typeof(ECommerce.Model.Controles.WebCompositeControl), "6"));
            return result.ToArray();
        }
        public static System.Type GetType(string ClaseNameSpace)
        {
            System.Type result=null;
            switch (ClaseNameSpace)
            {
                case "System.Web.UI.WebControls.WebControl":
                    result = typeof(System.Web.UI.WebControls.WebControl);
                    break;
                case "System.Web.UI.WebControls.CompositeControl":
                    result = typeof(System.Web.UI.WebControls.CompositeControl);
                    break;
                case "ECommerce.Model.Controles.WebCompositeControl":
                    result = typeof(ECommerce.Model.Controles.WebCompositeControl);
                    break;
                case "System.Web.UI.WebControls.Label":
                    result = typeof(System.Web.UI.WebControls.Label);
                    break;
                case "System.Web.UI.WebControls.LinkButton":
                    result = typeof(System.Web.UI.WebControls.LinkButton);
                    break;
                case "System.Web.UI.WebControls.Button":
                    result = typeof(System.Web.UI.WebControls.Button);
                    break;
                case "System.Web.UI.WebControls.ListItem":
                    result = typeof(System.Web.UI.WebControls.ListItem);
                    break;
                case "System.Web.UI.WebControls.Literal":
                    result = typeof(System.Web.UI.WebControls.Literal);
                    break;
                case "System.Web.UI.WebControls.Image":
                    result = typeof(System.Web.UI.WebControls.Image);
                    break;
                case "System.Web.UI.WebControls.ImageButton":
                    result = typeof(System.Web.UI.WebControls.ImageButton);
                    break;
                case "System.Web.UI.WebControls.TextBox":
                    result = typeof(System.Web.UI.WebControls.TextBox);
                    break;

                default:
                    throw new Exception("Clase no definida en ECommerce.Reflection.GetType");
            }
            return result;
        }

        internal static System.Web.UI.WebControls.WebControl GetWebControl(System.Web.UI.WebControls.WebControl webControl, Type Tipo, System.Web.UI.WebControls.CommandEventHandler CommandEvent, string CommandArgument, string ImageUrl)
        {
            System.Web.UI.WebControls.WebControl result = webControl;
            switch (Tipo.ToString())
            {
                case "System.Web.UI.WebControls.WebControl":
                    System.Web.UI.WebControls.WebControl WebControl = (System.Web.UI.WebControls.WebControl)webControl;
                    result = WebControl;
                    break;
                case "System.Web.UI.WebControls.CompositeControl":
                    System.Web.UI.WebControls.CompositeControl CompositeControl = (System.Web.UI.WebControls.CompositeControl)webControl;
                    result = CompositeControl;
                    break;
                case "ECommerce.Model.Controles.WebCompositeControl":
                    ECommerce.Model.Controles.WebCompositeControl WebCompositeControl = (ECommerce.Model.Controles.WebCompositeControl)webControl;
                    result = WebCompositeControl;
                    break;
                case "System.Web.UI.WebControls.Label":
                    System.Web.UI.WebControls.Label Label = (System.Web.UI.WebControls.Label)webControl;
                    result = Label;
                    break;
                case "System.Web.UI.WebControls.LinkButton":
                    System.Web.UI.WebControls.LinkButton LinkButton = (System.Web.UI.WebControls.LinkButton)webControl;
                    LinkButton.Command += CommandEvent;
                    LinkButton.CommandArgument = CommandArgument;
                    result = LinkButton;
                    break;
                case "System.Web.UI.WebControls.Button":
                    System.Web.UI.WebControls.Button Button = (System.Web.UI.WebControls.Button)webControl;
                    Button.Command += CommandEvent;
                    Button.CommandArgument = CommandArgument;
                    result = Button;
                    break;
                case "System.Web.UI.WebControls.ListItem":
                    //result = typeof(System.Web.UI.WebControls.ListItem);
                    break;
                case "System.Web.UI.WebControls.Literal":
                    //result = typeof(System.Web.UI.WebControls.Literal);
                    break;
                case "System.Web.UI.WebControls.Image":
                    System.Web.UI.WebControls.Image Image = (System.Web.UI.WebControls.Image)webControl;
                    Image.ImageUrl = ImageUrl;
                    result = Image;
                    break;
                case "System.Web.UI.WebControls.ImageButton":
                    System.Web.UI.WebControls.ImageButton ImageButton = (System.Web.UI.WebControls.ImageButton)webControl;
                    ImageButton.Command += CommandEvent;
                    ImageButton.CommandArgument = CommandArgument;
                    ImageButton.ImageUrl = ImageUrl;
                    result = ImageButton;
                    break;
                case "System.Web.UI.WebControls.TextBox":
                    //result = typeof(System.Web.UI.WebControls.TextBox);
                    break;

                default:
                    throw new Exception("Clase no definida en ECommerce.Reflection.GetWebControl");
            }
            return result;
        }
    }
}
